<?php
	class TaiKhoan
	{
		public $tk_username;
		public $tk_password;
		public $tk_ngay_tao;
		public $tk_email;
		public $tk_ho_ten;
		public $tk_gioi_tinh;
		public $tk_dia_chi;
		public $tk_dien_thoai;
		public $tk_avatar;
		public $tk_tinh_trang;
		public $tk_loai;
		
		public static function ThemTaiKhoan($taikhoan)
		{
			$str = $taikhoan->tk_password . $taikhoan->tk_username;
			$taikhoan->tk_password = md5($str);
			$query = "insert into Tai_Khoan(tk_username, tk_password, tk_email, tk_ho_ten, tk_gioi_tinh, tk_dia_chi, tk_dien_thoai, tk_avatar, tk_tinh_trang,tk_loai, tk_ngay_tao) values ('$taikhoan->tk_username', '$taikhoan->tk_password', '$taikhoan->tk_email', '$taikhoan->tk_ho_ten','$taikhoan->tk_gioi_tinh', '$taikhoan->tk_dia_chi', '$taikhoan->tk_dien_thoai', '$taikhoan->tk_avatar', '$taikhoan->tk_tinh_trang', '$taikhoan->tk_loai', '$taikhoan->tk_ngay_tao')";
			QuerySQL($query);
			StopConnection();
		}
		
		public static function KiemTraUserName($Username)
		{
			$query = "select * from tai_khoan where tk_username = '$Username'";
			$results = QuerySQL($query);
			$rows = mysql_num_rows($results);
			if($rows)
				return false;
			return true;
		}
		
		public static function Login($Username, $Password, & $role)
		{
			$str =  $Password . $Username ;
			$Password = md5($str);
			$query = "select * from tai_khoan where tk_username = '$Username' and tk_password = '$Password'";
			$results = QuerySQL($query);
			while($rows = mysql_fetch_array($results))
			{
				$role = $rows["tk_loai"];
				return true;
			}
			return false;			
		}
		
		public static function LayMaGianHang($username)
		{
			$query = "select * from gian_hang where gh_username = '$username'";
			$results = QuerySQL($query);
			while($rows = mysql_fetch_array($results))
			{
				return $rows["gh_ma"];
			}
		}
		 
	}
?>